package bsh;

import java.util.HashMap;
import java.util.Map;

/**
 * @author takeshi
 */
public class StackFrame {

    private final Map<String, Object> localVariables = new HashMap<String, Object>();

    private final String name;

    private final StackFrame parent;

    /**
     * @param name String
     * @param parent {@link StackFrame}
     */
    public StackFrame(String name, StackFrame parent) {
        super();
        this.parent = parent;
        this.name = name;
    }

    /**
     * @param varName String
     * @param value Object
     */
    public void addVariable(String varName, Object value) {
        if (value == null) {
            localVariables.remove(varName);
        } else {
            localVariables.put(varName, value);
        }
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the parent
     */
    public StackFrame getParent() {
        return parent;
    }

    /**
     * @return the localVariables
     */
    public Map<String, Object> getLocalVariables() {
        return localVariables;
    }

}
